(function($){
    function formResult(msg, state) {
        layer.closeAll();
        if(state == 0) {
            layer.alert(msg, {icon: 5});
        }else {
            layer.alert(msg, {icon: 1},function(){
                parent.location.reload(true);
            });

        }
    }
    function openPage() {
        var obj = $(this);
        var url = obj.attr('dhref');
        var title = obj.attr('dtitle');
        layer.open({
            type: 2,
            title: title,
            shadeClose: false,
            shade: 0.8,
            maxmin: true,
            area: ['570px', '350px'],
            content: url
        });
    }
    $(function(){
        window.formResult = formResult;
        $('.btnAdd').on('click', openPage);

        $('.a_slideThree').click(function(e){
            e.stopPropagation()
            $('.switchBtn').click();
        });
        $('.switchBtn').click(function(e){
            e.stopPropagation()
        });

        if($('#slideThree').is(':checked')){
            $('.guide').show();
        }else{
            $('.guide').hide();
        }
         $('.switchBtn').each(function(){
             $(this).click(function(){
                 if($('#slideThree').is(':checked')){
                     localStorage.setItem('status','off');
                     $('.guide').hide();
                 } else{
                     localStorage.setItem('status','on');
                     $('.guide').show();
                 }
             });
             });
        if(localStorage.getItem('status')=='on'){
            $('#slideThree').attr('checked',true);
            $('.guide').show();
        } else if(localStorage.getItem('status')=='off'){
            $('#slideThree').attr('checked',false);
            $('.guide').hide();
        }

        var $top = $('.imgBg').offset().top;
        $('.aniPic').css('top',function(){
            return $top + 250;
        });

        if (localStorage.pagecount)
        {
            localStorage.pagecount=Number(localStorage.pagecount) +1;
        }
        else
        {
            localStorage.pagecount=1;
            $('.switchBox').show();
        }
        if(localStorage.pagecount>1){
            $('.switchBox').hide();
            $('.aniPic').hide();
            $('.rightBtn').removeClass('open');
        } else {
            $('.switchBox').show();
            $('.aniPic').show();
            $('.rightBtn').addClass('open');
        }
        $('.aniPic').click(function(){
            $(this).remove();
            $('.switchBox').remove();
        });

    });


})(jQuery);